using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDLDEF
    {
        public DataRow Convert2DLDEF(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDLDEF(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DLDMANDANT"] = " ".PadRight(2 ); 
         dwReturn["DLDNAME"] = " ".PadRight(10 ); 
         dwReturn["DLDSPRKZ"] = " ".PadRight(2 ); 
         dwReturn["DLDFELD1"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD2"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD3"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD4"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD5"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD6"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD7"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD8"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD9"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD10"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD11"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD12"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD13"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD14"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD15"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD16"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD17"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD18"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD19"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD20"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD21"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD22"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD23"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD24"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD25"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD26"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD27"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD28"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD29"] = " ".PadRight(56 ); 
         dwReturn["DLDFELD30"] = " ".PadRight(56 ); 
         dwReturn["DLDFILLER"] = " ".PadRight(56 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDLDEF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDLDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDLDEF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDLDEF(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDLDEF(dwLocal, ITXDBVERSION);
            }
            UpdateDLDEF(dwLocal);
        }
        public void InsertDLDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DLDEF(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDLDEF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DLDEF WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DLDEF  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DLDEF";
            Return = Result;
            return Return;
        }
        public void DeleteDLDEF(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DLDEF   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDLDEF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DLDEF SET "
                    +"DLDMANDANT= :DLDMANDANT,"
                    +"DLDNAME= :DLDNAME,"
                    +"DLDSPRKZ= :DLDSPRKZ,"
                    +"DLDFELD1= :DLDFELD1,"
                    +"DLDFELD2= :DLDFELD2,"
                    +"DLDFELD3= :DLDFELD3,"
                    +"DLDFELD4= :DLDFELD4,"
                    +"DLDFELD5= :DLDFELD5,"
                    +"DLDFELD6= :DLDFELD6,"
                    +"DLDFELD7= :DLDFELD7,"
                    +"DLDFELD8= :DLDFELD8,"
                    +"DLDFELD9= :DLDFELD9,"
                    +"DLDFELD10= :DLDFELD10,"
                    +"DLDFELD11= :DLDFELD11,"
                    +"DLDFELD12= :DLDFELD12,"
                    +"DLDFELD13= :DLDFELD13,"
                    +"DLDFELD14= :DLDFELD14,"
                    +"DLDFELD15= :DLDFELD15,"
                    +"DLDFELD16= :DLDFELD16,"
                    +"DLDFELD17= :DLDFELD17,"
                    +"DLDFELD18= :DLDFELD18,"
                    +"DLDFELD19= :DLDFELD19,"
                    +"DLDFELD20= :DLDFELD20,"
                    +"DLDFELD21= :DLDFELD21,"
                    +"DLDFELD22= :DLDFELD22,"
                    +"DLDFELD23= :DLDFELD23,"
                    +"DLDFELD24= :DLDFELD24,"
                    +"DLDFELD25= :DLDFELD25,"
                    +"DLDFELD26= :DLDFELD26,"
                    +"DLDFELD27= :DLDFELD27,"
                    +"DLDFELD28= :DLDFELD28,"
                    +"DLDFELD29= :DLDFELD29,"
                    +"DLDFELD30= :DLDFELD30,"
                    +"DLDFILLER= :DLDFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DLDMANDANT", OracleType.NVarChar).Value = dwData["DLDMANDANT"].ToString(); 
          or1.Parameters.Add("DLDNAME", OracleType.NVarChar).Value = dwData["DLDNAME"].ToString(); 
          or1.Parameters.Add("DLDSPRKZ", OracleType.NVarChar).Value = dwData["DLDSPRKZ"].ToString(); 
          or1.Parameters.Add("DLDFELD1", OracleType.NVarChar).Value = dwData["DLDFELD1"].ToString(); 
          or1.Parameters.Add("DLDFELD2", OracleType.NVarChar).Value = dwData["DLDFELD2"].ToString(); 
          or1.Parameters.Add("DLDFELD3", OracleType.NVarChar).Value = dwData["DLDFELD3"].ToString(); 
          or1.Parameters.Add("DLDFELD4", OracleType.NVarChar).Value = dwData["DLDFELD4"].ToString(); 
          or1.Parameters.Add("DLDFELD5", OracleType.NVarChar).Value = dwData["DLDFELD5"].ToString(); 
          or1.Parameters.Add("DLDFELD6", OracleType.NVarChar).Value = dwData["DLDFELD6"].ToString(); 
          or1.Parameters.Add("DLDFELD7", OracleType.NVarChar).Value = dwData["DLDFELD7"].ToString(); 
          or1.Parameters.Add("DLDFELD8", OracleType.NVarChar).Value = dwData["DLDFELD8"].ToString(); 
          or1.Parameters.Add("DLDFELD9", OracleType.NVarChar).Value = dwData["DLDFELD9"].ToString(); 
          or1.Parameters.Add("DLDFELD10", OracleType.NVarChar).Value = dwData["DLDFELD10"].ToString(); 
          or1.Parameters.Add("DLDFELD11", OracleType.NVarChar).Value = dwData["DLDFELD11"].ToString(); 
          or1.Parameters.Add("DLDFELD12", OracleType.NVarChar).Value = dwData["DLDFELD12"].ToString(); 
          or1.Parameters.Add("DLDFELD13", OracleType.NVarChar).Value = dwData["DLDFELD13"].ToString(); 
          or1.Parameters.Add("DLDFELD14", OracleType.NVarChar).Value = dwData["DLDFELD14"].ToString(); 
          or1.Parameters.Add("DLDFELD15", OracleType.NVarChar).Value = dwData["DLDFELD15"].ToString(); 
          or1.Parameters.Add("DLDFELD16", OracleType.NVarChar).Value = dwData["DLDFELD16"].ToString(); 
          or1.Parameters.Add("DLDFELD17", OracleType.NVarChar).Value = dwData["DLDFELD17"].ToString(); 
          or1.Parameters.Add("DLDFELD18", OracleType.NVarChar).Value = dwData["DLDFELD18"].ToString(); 
          or1.Parameters.Add("DLDFELD19", OracleType.NVarChar).Value = dwData["DLDFELD19"].ToString(); 
          or1.Parameters.Add("DLDFELD20", OracleType.NVarChar).Value = dwData["DLDFELD20"].ToString(); 
          or1.Parameters.Add("DLDFELD21", OracleType.NVarChar).Value = dwData["DLDFELD21"].ToString(); 
          or1.Parameters.Add("DLDFELD22", OracleType.NVarChar).Value = dwData["DLDFELD22"].ToString(); 
          or1.Parameters.Add("DLDFELD23", OracleType.NVarChar).Value = dwData["DLDFELD23"].ToString(); 
          or1.Parameters.Add("DLDFELD24", OracleType.NVarChar).Value = dwData["DLDFELD24"].ToString(); 
          or1.Parameters.Add("DLDFELD25", OracleType.NVarChar).Value = dwData["DLDFELD25"].ToString(); 
          or1.Parameters.Add("DLDFELD26", OracleType.NVarChar).Value = dwData["DLDFELD26"].ToString(); 
          or1.Parameters.Add("DLDFELD27", OracleType.NVarChar).Value = dwData["DLDFELD27"].ToString(); 
          or1.Parameters.Add("DLDFELD28", OracleType.NVarChar).Value = dwData["DLDFELD28"].ToString(); 
          or1.Parameters.Add("DLDFELD29", OracleType.NVarChar).Value = dwData["DLDFELD29"].ToString(); 
          or1.Parameters.Add("DLDFELD30", OracleType.NVarChar).Value = dwData["DLDFELD30"].ToString(); 
          or1.Parameters.Add("DLDFILLER", OracleType.NVarChar).Value = dwData["DLDFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
